<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div class="" id="app">
        <table class="table table-hover">
            <thead>
                <tr>
                    <th>编号</th>
                    <th>电影名</th>
                    <th>评分</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="item in movies" :key="item.name">
                    <td>{{item._id}}</td>
                    <td>{{item.name}}</td>
                    <td>{{item.rating}}</td>
                    <td>
                        <button type="button" class="btn btn-danger" @click="doDelete(item._id)">delete</button>
                        
                        <button type="button" class="btn btn-warning" @click="doUpdate()">update</button>
                        
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <script>
        new Vue({
            el:"#app",
            data:{
                movies:[]
            },
            mounted() {
                this.request();
            },
            methods: {
                //请求数据
                request(){
                    $.ajax({
                    type: "get",
                    url: "http://localhost:8080/top250",
                    dataType: 'json'
                    }).then(res=>{
                        this.movies = res;
                    });
                },
                doDelete(id){
                    console.log(id);
                    $.ajax({
                        type: "post",
                        url: "http://localhost:8080/doDelete",
                        dataType: "json",
                        data:{
                            id
                        }
                    }).then(res=>{
                        console.log(res);
                    });
                    // 更新本地数据movies
                    this.request();
                }
            },
        })
        
    </script>
        <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
        <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
</body>
</html>